package com.clouddot.baipai.presenter;


import com.clouddot.baipai.contract.ISettingActivityContract;
import com.clouddot.baipai.http.entity.response.bindBanPaiResponse;
import com.clouddot.baipai.http.entity.response.getAllClassResponse;

import org.wxy.sdk.base.impl.BasePresenterImpl;

import java.util.ArrayList;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;

public class SettingActivityPresenter extends BasePresenterImpl<ISettingActivityContract.IView, ISettingActivityContract.IModel> implements ISettingActivityContract.IPresenter {
    public SettingActivityPresenter(ISettingActivityContract.IView view, ISettingActivityContract.IModel model) {
        super(view, model);
    }


    @Override
    public void bindBanPai(String ClassId, String carddevid) {
        Subscription subscription = mModel.bindBanPai("ClassBind", ClassId, carddevid)
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<bindBanPaiResponse>() {
                               @Override
                               public void call(bindBanPaiResponse response) {
                                   mView.success(1, response);
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(1, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }

    @Override
    public void getAllClassList() {
        Subscription subscription = mModel.getAllClassList("QueryClassList")
                .subscribeOn(Schedulers.newThread())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Action1<ArrayList<getAllClassResponse>>() {
                               @Override
                               public void call(ArrayList<getAllClassResponse> response) {
                                   if (!response.isEmpty()) {
                                       mView.success(2, response);
                                   } else {
                                       mView.fail(2, "暂时无班级");

                                   }
                               }
                           }
                        , new Action1<Throwable>() {
                            @Override
                            public void call(Throwable throwable) {
                                mView.fail(2, throwable.getMessage());

                            }
                        });
        addSubscription(subscription);
    }
}
